import { CodeDynamicComponent } from '@sfkj/sfw-dc-ui';
import { useSearchParams } from '@umijs/max';
import { Empty, Typography } from 'antd';
import lodash from 'lodash';
import React from 'react';

/**
 * 从 url 中获取组件 code 并加载组件
 * @constructor
 */
const UrlCodeDynamicComponent: React.FC = () => {
  let [searchParams] = useSearchParams();

  const cc = searchParams.get('cc');
  if (!cc || lodash.isEmpty(cc)) {
    return (
      <Empty
        description={
          <>
            <Typography.Title level={5}>
              请传入动态组件编码，例如：cc=dynamicComponentCode
            </Typography.Title>
            <Typography.Text>cc 支持的值请查询[动态组件]数据</Typography.Text>
          </>
        }
      />
    );
  }

  return <CodeDynamicComponent componentCode={cc.toString()} />;
};

export default UrlCodeDynamicComponent;
